﻿using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;

namespace PlanningGIS.Draw
{
    public class SelectElement2 : ControlsSelectToolClass
    {
        private string caption;
        private string tooltip;
        private IPageLayoutControl PageLayoutControl;

        public SelectElement2()
        {
            caption = "选择图形";
            tooltip = caption;
        }

        public override bool Enabled
        {
            get { return base.Enabled; }
        }

        public override bool Checked
        {
            get { return base.Checked; }
        }

        public override string Name
        {
            get { return base.Name; }
        }

        public override string Caption
        {
            get { return caption; }
        }

        public override string Tooltip
        {
            get { return tooltip; }
        }

        public override string Message
        {
            get { return base.Message; }
        }

        public override string HelpFile
        {
            get { return base.HelpFile; }
        }

        public override int HelpContextID
        {
            get { return base.HelpContextID; }
        }

        public override int Bitmap
        {
            get { return base.Bitmap; }
        }

        public override string Category
        {
            get { return base.Category; }
        }

        public override int Cursor
        {
            get { return base.Cursor; }
        }

        public override void OnCreate(object hook)
        {
            base.OnCreate(hook);

            if (hook is IToolbarControl)
            {
                IToolbarControl pTB = hook as IToolbarControl;
                PageLayoutControl = (IPageLayoutControl)pTB.Buddy;
            }
        }

        public override void OnClick()
        {
            base.OnClick();
        }

        public override void OnMouseDown(int button, int shift, int x, int y)
        {
            base.OnMouseDown(button, shift, x, y);
        }

        public override void OnMouseMove(int button, int shift, int x, int y)
        {
            base.OnMouseMove(button, shift, x, y);
        }

        public override void OnMouseUp(int button, int shift, int x, int y)
        {
            base.OnMouseUp(button, shift, x, y);
        }

        public override void OnDblClick()
        {
            base.OnDblClick();
            IGraphicsContainerSelect pGraphicsContainerSelect = (IGraphicsContainerSelect)PageLayoutControl.PageLayout;

            IEnumElement pEnumElement = pGraphicsContainerSelect.SelectedElements;
            IElement pElement = pEnumElement.Next();

            if (pElement == null)
                return;

            if (pElement.Locked == true)
                return;

            if (pElement is ITextElement)
            {
                ITextElement pTextElement = (ITextElement)pElement;
                FrmEditTextElement thisFrm = new FrmEditTextElement();
                thisFrm.TextElement = pTextElement;
                thisFrm.ShowDialog();
                PageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing);
            }
        }

        public override void OnKeyDown(int keyCode, int shift)
        {
            base.OnKeyDown(keyCode, shift);
        }

        public override void OnKeyUp(int keyCode, int shift)
        {
            base.OnKeyUp(keyCode, shift);
        }

        public override bool OnContextMenu(int x, int y)
        {
            return base.OnContextMenu(x, y);
        }

        public override void Refresh(int hdc)
        {
            base.Refresh(hdc);
        }

        public override bool Deactivate()
        {
            return base.Deactivate();
        }
    }
}
